// node引入包名
const iot = require('alibabacloud-iot-device-sdk');
// 浏览器、微信小程序，支付宝小程序引入./dist编译的js文件
// const iot = require('./dist/alibabacloud-iot-device-sdk.js');
// js版本下载地址：
//    https://github.com/aliyun/alibabacloud-iot-device-sdk/tree/master/dist  或
//    alibabacloud-iot-device-sdk.js 下载地址 https://unpkg.com/alibabacloud-iot-device-sdk@1.2.4/dist/alibabacloud-iot-device-sdk.js  或
//    alibabacloud-iot-device-sdk.min.js 下载地址 https://unpkg.com/alibabacloud-iot-device-sdk@1.2.4/dist/alibabacloud-iot-device-sdk.min.js  
//  

const device = iot.device({
    productKey: 'a1h6PXkhk3H',
    deviceName: 'ming1',
    deviceSecret: 'fVJEWMzRAhw9miEHfHb8sKV6HCsFkoVu',
    // 支付宝小程序和微信小程序额外需要配置协议参数
    // "protocol": 'alis://', "protocol": 'wxs://',
});
device.subscribe('/a1h6PXkhk3H/ming1/get');
device.on('connect', () => {
    console.log('connect successfully!');
    device.publish('/a1h6PXkhk3H/ming1/update', 'hello world!');
});
device.on('message', (topic, payload) => {
    console.log(topic, payload.toString());
});